<?php
defined('CITY_BAO') or exit('Access Denied');
require CB_CORE.'modules/'.$config_module['module'].'/common.inc.php';
$action = $request->getActionName();
$profile = $cbdb->get_row('SELECT * FROM {#cbdbPrefix}member_profile WHERE userid='.$user->userid);
$tpl->assign('profile',$profile);
if($action == 'edit'){
	$form_validate = form_validate('profile_edit');
	if($request->isPost()){
		$validate = trim($request->getParam('validate'));
		if($validate == $form_validate){
			$realname = trim($request->getParam('realname'));
			$gender = trim($request->getParam('gender'));
			$birthyear = trim($request->getParam('birthyear'));
			$birthmonth = trim($request->getParam('birthmonth'));
			$birthday = trim($request->getParam('birthday'));
			$constellation = trim($request->getParam('constellation'));
			$zodiac = trim($request->getParam('zodiac'));
			$resideprovince = trim($request->getParam('resideprovince'));
			$residecity = trim($request->getParam('residecity'));
			$residedist = trim($request->getParam('residedist'));
			$education = trim($request->getParam('education'));
			$marital = trim($request->getParam('marital'));
			$bloodtype = trim($request->getParam('bloodtype'));
			$occupation = trim($request->getParam('occupation'));
			$company = trim($request->getParam('company'));
			$revenue = trim($request->getParam('revenue'));
			$address = trim($request->getParam('address'));
			$zipcode = trim($request->getParam('zipcode'));
			$telephone = trim($request->getParam('telephone'));
			$qq = trim($request->getParam('qq'));
			$msn = trim($request->getParam('msn'));
			$question = trim($request->getParam('question'));
			$answer = trim($request->getParam('answer'));
			$update_data = array(
				'realname'=>$realname,
				'gender'=>$gender,
				'birthyear'=>$birthyear,
				'birthmonth'=>$birthmonth,
				'birthday'=>$birthday,
				'constellation'=>$constellation,
				'zodiac'=>$zodiac,
				'resideprovince'=>$resideprovince,
				'residecity'=>$residecity,
				'residedist'=>$residedist,
				'education'=>$education,
				'marital'=>$marital,
				'bloodtype'=>$bloodtype,
				'occupation'=>$occupation,
				'company'=>$company,
				'revenue'=>$revenue,
				'address'=>$address,
				'zipcode'=>$zipcode,
				'telephone'=>$telephone,
				'qq'=>$qq,
				'msn'=>$msn,
				'question'=>$question,
				'answer'=>$answer
			);
			if($profile->idcardtype == ''){
				$update_data['idcardtype'] = trim($request->getParam('idcardtype'));
				$update_data['idcard'] = trim($request->getParam('idcard'));
			}
			$result = $cbdb->update('{#cbdbPrefix}member_profile',$update_data,array('userid'=>$user->userid));
			if($result){
				redirect(INSTALL_PATH.'member/profile.php');
			}else{
				show_message('用户资料修改失败！<br />可能原因:'.$cbdb->get_last_error(),'-1');
			}
		}else{
			show_message('数据来源校验失败！','-1');
		}
	}else{
		$tpl->assign('title',"修改基本资料");
		$tpl->assign('validate',$form_validate);
		$tpl->assign('education_options',include CB_DATA.'options/education.php');
		$tpl->assign('idcardtype_options',include CB_DATA.'options/idcardtype.php');
		$tpl->assign('question_options',include CB_DATA.'options/question.php');
		$tpl->assign('blood_options',include CB_DATA.'options/blood.php');
		$tpl->assign('marital_options',include CB_DATA.'options/marital.php');
		$tpl->assign('income_options',include CB_DATA.'options/income.php');
		$tpl->display('member/profile-edit.tpl');
	}
}else{
	$tpl->assign('title',"基本资料");
	$tpl->display('member/profile.tpl');
}